{include file="base/_meta" /}
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <!-- 头部 -->
    <div class="layui-header">
        <div class="layui-logo">
            <img src="{$siteOptions.site_logo|default='__ADMIN__/easyweb/images/logo.png'}"/>
            <cite>&nbsp;{$siteOptions.site_title}</cite>
        </div>
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item" lay-unselect>
                <a ew-event="flexible" title="侧边伸缩"><i class="layui-icon layui-icon-shrink-right"></i></a>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a ew-event="refresh" title="刷新"><i class="layui-icon layui-icon-refresh-3"></i></a>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item" lay-unselect>
                <a id="empty_cache" title="清空缓存">
                    <i class="layui-icon layui-icon-delete"></i>
                </a>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a>
                    <img src="{$admin.headimg|default=''}" class="layui-nav-img">
                    <cite>{$admin.nick_name}</cite>
                </a>
                <dl class="layui-nav-child">
                    <dd lay-unselect><a ew-href="{:url('index/user_info')}">个人中心</a></dd>
                    <dd lay-unselect><a ew-event="psw">修改密码</a></dd>
                    <hr>
                    <dd lay-unselect>
                        <a ew-event="logout" data-url="{:url('login/login_out')}">退出</a>
                    </dd>
                </dl>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a id="theme" title="主题"><i class="layui-icon layui-icon-more-vertical"></i></a>
            </li>
        </ul>
    </div>

    <!-- 侧边栏 -->
    <div class="layui-side">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree" lay-filter="admin-side-nav" lay-shrink="all"></ul>
        </div>
    </div>

    <script id="sideNav" type="text/html">
        {{#  layui.each(d, function(index, item){ }}
        <li class="layui-nav-item">
            <a lay-href="{{item.url}}"><i class="{{item.icon}}"></i>&emsp;<cite>{{item.name }}</cite></a>
            {{# if(item.subMenus&&item.subMenus.length>0){ }}
            <dl class="layui-nav-child">
                {{# layui.each(item.subMenus, function(index, subItem){ }}
                <dd>
                    <a lay-href="{{ subItem.url }}">{{ subItem.name }}</a>
                    {{# if(subItem.subMenus&&subItem.subMenus.length>0){ }}
                    <dl class="layui-nav-child">
                        {{# layui.each(subItem.subMenus, function(index, thrItem){ }}
                        <dd><a lay-href="{{ thrItem.url }}">{{ thrItem.name }}</a></dd>
                        {{# }); }}
                    </dl>
                    {{# } }}
                </dd>
                {{# }); }}
            </dl>
            {{# } }}
        </li>
        {{#  }); }}
    </script>
    <!-- 主体部分 -->
    <div class="layui-body"></div>
    <!-- 底部 -->
    <div class="layui-footer layui-text">
        copyright © 2020 <a href="http://easyweb.vip" target="_blank">easyweb.vip</a> all rights reserved.
        <span class="pull-right">Version 3.1.7</span>
    </div>
</div>


{include file="base/_script" /}
<script>
    layui.use(['index', 'element', 'admin', 'laytpl'], function () {
        var $ = layui.jquery,
            index = layui.index
            , element = layui.element
            , admin = layui.admin
            , laytpl = layui.laytpl;

        // 默认加载主页
        index.loadHome({
            menuPath: "{:url('index/console')}",
            menuName: '<i class="layui-icon layui-icon-home"></i>'
        });


        // 将页面本地缓存
        // 判断是不是有本地缓存，如果没有
        if (localStorage.getItem('sideMenu') == null) {
            $.post("{:url('auth/get_admin_menu')}", function (res) {
                localStorage.setItem('sideMenu', JSON.stringify(res))
                laytpl(sideNav.innerHTML).render(res.data, function (html) {
                    $('[lay-filter=admin-side-nav]').html(html);
                    element.render('nav', 'admin-side-nav');  // 这里非常重要
                });
            }, 'json');
        } else {
            // 如果有
            let res = JSON.parse(localStorage.getItem('sideMenu'))
            // 判断缓存中是不是有菜单内容，如果没有
            if (res.data == '') {
                $.post("{:url('auth/get_admin_menu')}", function (res) {
                    localStorage.setItem('sideMenu', JSON.stringify(res))
                    laytpl(sideNav.innerHTML).render(res.data, function (html) {
                        $('[lay-filter=admin-side-nav]').html(html);
                        element.render('nav', 'admin-side-nav');  // 这里非常重要
                    });
                }, 'json');
            } else {
                laytpl(sideNav.innerHTML).render(res.data, function (html) {
                    $('[lay-filter=admin-side-nav]').html(html);
                    element.render('nav', 'admin-side-nav');  // 这里非常重要
                });
            }
        }

        // 主题点击事件
        $("#theme").click(function () {
            admin.popupRight({
                type: 2,
                content: 'tpl-theme.html'
            });
        })

        // 清空缓存
        $("#empty_cache").click(function () {
            // 清空所有本地缓存
            localStorage.clear()
            //询问框
            layer.confirm('您确定要清除所有缓存吗？', {
                    btn: ['确定', '取消'],
                    title:"提示"
                },
                function () {
                    $.get("{:url('login/clear_cache')}", function (info) {
                        layer.msg(info.msg,{icon:1,time:1500},function () {
                            window.location.reload()
                        });
                    });
                },
                function () {
                });
        })
    });
</script>
</body>
</html>
